package com.qf.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 汤奇
 * @version V1.0
 * @Project BookPro
 * @Package com.qf.controller
 * @Description:
 * @Date 2022/6/8 22:30
 */
@Controller
@RequestMapping("/captcha")
public class CodeController {
    /**
     * @return 跳转到验证码页面
     */
    @RequestMapping("/toCode")
    public String toCode(){
        return "code";
    }

    /**
     * 校验验证码
     * @param captcha 前端传来的数据
     * @param request 域
     * @return 页面跳转
     */
    @RequestMapping("/test1")
    public String test1(String captcha, HttpServletRequest request){
        //1.从session会话中获取验证码
        String captchaSession = (String) request.getSession().getAttribute("captcha");
        //2.比较验证码是否相等
        if (captchaSession.equalsIgnoreCase(captcha)) {
            System.out.println("验证码正确");
        } else {
            System.out.println("验证码错误");
        }
        return "hello";
    }
}
